package com.webwork.mood.record.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webwork.mood.record.dao.LevelReasonDao;
import com.webwork.mood.record.dao.LevelScoreDao;
import com.webwork.mood.record.dataobject.LevelReason;
import com.webwork.mood.record.dataobject.LevelScore;
import com.webwork.mood.record.service.LevelService;
import com.webwork.mood.util.Paging;

@Service
public class LevelServiceImpl implements LevelService {

	@Autowired
	private LevelScoreDao levelScoreDao;

	@Autowired
	private LevelReasonDao levelReasonDao;

	@Override
	public void update(LevelScore o) {
		levelScoreDao.update(o);
	}

	@Override
	public List<LevelScore> query(LevelScore o) {
		return levelScoreDao.query(o, 0, 0);
	}

	@Override
	public List<LevelScore> query(LevelScore o, Paging page) {
		return levelScoreDao.query(o, page.getCurrPage(), page.getPageSize());
	}

	@Override
	public int count(LevelScore o) {
		return levelScoreDao.count(o);
	}

	@Override
	public void insert(LevelReason o) {
		levelReasonDao.insert(o);
	}

	@Override
	public void update(LevelReason o) {
		levelReasonDao.update(o);
	}

	@Override
	public void delete(LevelReason o) {
		levelReasonDao.delete(o);
	}

	@Override
	public List<LevelReason> query(LevelReason o) {
		return levelReasonDao.query(o, 0, 0);
	}
	
	@Override
	public Map<String, List<String>> getReasonMap() {
		List<LevelReason> lrs = this.query(new LevelReason());
		Map<String, List<String>> ret = new HashMap<String, List<String>>();
		for (LevelReason lr : lrs) {
			List<String> strs = ret.get(lr.getLevel().name());
			if (strs == null) {
				strs = new ArrayList<String>();
				ret.put(lr.getLevel().name(), strs);
			}
			strs.add(lr.getReason());
		}
		return ret;
	}

	@Override
	public List<LevelReason> query(LevelReason o, Paging page) {
		return levelReasonDao.query(o, page.getCurrPage(), page.getPageSize());
	}

	@Override
	public int count(LevelReason o) {
		return levelReasonDao.count(o);
	}
	

}
